package isssr.bean.control;

import isssr.bean.entity.OrganizationalGoal;
import isssr.bean.entity.User;
import isssr.bean.utility.HibernateUtility;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class RetrieveGoalListControl implements Serializable {

	
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 3403544595563392501L;
	
	
	public RetrieveGoalListControl(){}

	public List<OrganizationalGoal> retrieveGoalListByOwner(User owner)
	{
		OrganizationalGoal g_template = new OrganizationalGoal();
		g_template.setGoalOwner(owner);
		return this.retrieveGoalsByTemplate(g_template);
		/*
		List<OrganizationalGoal> retrieved_goals = new ArrayList<OrganizationalGoal>();
		Iterator rg_iterator = HibernateUtility.getGoalsByOwner(owner);
		while(rg_iterator.hasNext())
		{
			OrganizationalGoal retrieved_goal = (OrganizationalGoal) rg_iterator.next();
			retrieved_goals.add(retrieved_goal);
		}
		
		return retrieved_goals;
		*/
	}
	
	public List<OrganizationalGoal> retrieveGoalListByEnactor(User enactor)
	{
		OrganizationalGoal g_template = new OrganizationalGoal();
		g_template.setGoalEnactor(enactor);
		return this.retrieveGoalsByTemplate(g_template);
	}
	
	public List<OrganizationalGoal> retrieveGoalListBySuper()
	{
		return new ArrayList<OrganizationalGoal>();
	}
	
	private List<OrganizationalGoal> retrieveGoalsByTemplate(OrganizationalGoal g_template) 
	{
		List<OrganizationalGoal> retrieved_goals = new ArrayList<OrganizationalGoal>();
		Iterator rg_iterator = null;
		
		try {
			rg_iterator = g_template.loadSiblings();
		} catch (Exception e) {
			e.printStackTrace();
			return retrieved_goals;
		}
	
		while(rg_iterator.hasNext())
		{
			OrganizationalGoal retrieved_goal = (OrganizationalGoal) rg_iterator.next();
			retrieved_goals.add(retrieved_goal);
		}
		
		return retrieved_goals;
	}
	
}